package com.abel.bigwater.data.sanchuan

import io.netty.buffer.Unpooled
import org.joda.time.DateTime
import org.junit.Assert.assertEquals
import org.junit.Test

class FetchDataTests {
    @Test
    fun testMonthBill() {
        val mbill = FetchData(null)
        mbill.cmd = FetchCmdType.MonthBill

        val buf = Unpooled.buffer()
        mbill.fillBuffer(buf)

        assertEquals("should contain 0x01", 1, buf.readableBytes())
        assertEquals(1, buf.readByte().toInt())
    }

    @Test
    fun testDayBill() {
        val bill = FetchData(null)
        bill.cmd = FetchCmdType.DayBill

        val buf = Unpooled.buffer()
        bill.fillBuffer(buf)

        assertEquals("should contain 0x02", 1, buf.readableBytes())
        assertEquals(2, buf.readByte().toInt())
    }

    @Test
    fun testWeekDetail() {
        val bill = FetchData(null)
        bill.cmdWeekDetail = FetchCmdWeekDetail(0x03)
        bill.startTime = DateTime(2018, 8, 1, 8, 0)
        bill.timeInterval = 0x0F
        bill.pointNumber = 5

        val buf = Unpooled.buffer()
        bill.fillBuffer(buf)

        assertEquals("should contain 0x03", 9, buf.readableBytes())
        assertEquals(0x032018080108000F, buf.readLong())
        assertEquals(0x05, buf.readByte().toInt())

    }

    @Test
    fun testWeekDetailPressure() {
        val bill = FetchData(null)
        bill.cmdWeekDetail = FetchCmdWeekDetail(0)
        bill.cmdWeekDetail!!.dataType = FetchCmdWeekDetail.DetailDataType.Pressure

        bill.startTime = DateTime(2018, 8, 1, 8, 0)
        bill.timeInterval = 0x0F
        bill.pointNumber = 3

        val buf = Unpooled.buffer()
        bill.fillBuffer(buf)

        assertEquals("should contain 0x03", 9, buf.readableBytes())
        assertEquals(0x052018080108000F, buf.readLong())
        assertEquals(0x03, buf.readByte().toInt())

    }
}